package com.lin.csdn.controller;

import com.lin.csdn.model.po.Messege;
import com.lin.csdn.service.impl.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/SignServlet")
public class SignServlet extends HttpServlet {
    /**
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     *
     * 注册账号事务
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding ("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        Messege signUser;
        //获取req数据
        String email=req.getParameter("email");
        String password=req.getParameter("password");
        String name=req.getParameter("name");

        UserService signService=new UserService();
        signUser=signService.sign(name,email,password);

        PrintWriter writer = resp.getWriter(); //响应流
        if(signUser.getCode()==200){
            writer.print("注册成功");
        }
        else{
            writer.print("注册错误");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
